package com.fillifesoft.magicHitter.controller;

import java.util.Random;

import com.fillifesoft.magicHitter.MagicHitter;
import com.fillifesoft.magicHitter.manager.RepositoryManager;
import com.fillifesoft.magicHitter.output.Output;

public class Generator {
	
	public RepositoryManager repoManager;
	public int repeatCount;
	public Output output;
	
	public Generator(int repeatCount) {
		repoManager = new RepositoryManager();
		this.repeatCount = repeatCount;
	}
	
	public void generate() {
		for(int i=0; i<repeatCount; i++) {
			System.out.println(String.format("%d'th Generating... ", i+1));
			repoManager.init();
			
			try {
				Random random = new Random();
				for(int j=0; j<MagicHitter.REPEAT_COUNT; j++) {
					if(j % (int)(MagicHitter.REPEAT_COUNT / 10) == 0) {
						System.out.print(".");
					}
					
					int waitTime = random.nextInt(10);
					Thread.sleep(waitTime);
					int number = (int)(System.currentTimeMillis() % MagicHitter.REPO_LEN + 1);
					repoManager.countNumber(number);
				}
				
				repoManager.output();
			}
			catch(InterruptedException e) {
				e.printStackTrace();
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
}
